package com.ebelter.myehc.ui.fragments.trends;



import com.ebelter.btcomlib.bases.fragment.BaseFragment;
import com.ebelter.btcomlib.models.bluetooth.products.bloodoxgen.BOManager;
import com.ebelter.btcomlib.utils.AppUtils;
import com.ebelter.btcomlib.utils.CommonUtils;
import com.ebelter.btcomlib.utils.NumUtils;
import com.ebelter.btcomlib.utils.TimeUtils;
import com.ebelter.btcomlib.views.ChartView3;
import com.ebelter.btcomlib.views.CombinView7;
import com.ebelter.btcomlib.views.CombinView8;
import com.ebelter.myehc.R;
import com.ebelter.myehc.models.http.response.device_resports.BO_R;
import com.ebelter.myehc.utils.EHCCommonUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.ebelter.btcomlib.bases.activity.BaseActivity.getString_;
import static com.ebelter.myehc.ui.fragments.trends.Trend_XueYa_Fragment.setCb8SrcRes;
import static com.ebelter.myehc.ui.fragments.trends.Trend_XueYa_Fragment.setCb8Title;

/**
 * 趋势血压
 */

public class Trend_XueYang_Fragment extends BaseFragment {
    public static final String TAG = "Trend_XueYang_Fragment";

    private static final int[] levelColors={0xff189ae5,0xff18d5e5,0xff14e34e};

    CombinView7 xy_cb7;
    CombinView8 xueyang_xy_cb8;
    CombinView8 xueyang_xl_cb8;

    ChartView3 trend_xy_xy_chartview3;
    ChartView3 trend_xy_xl_chartview3;

    @Override
    protected int setLayoutResouceId() {
        return R.layout.fragment_trend_xueyang;
    }


    public void setReportData(BO_R reportData) {
        if (reportData==null||reportData.resultCode!=1||reportData.resultData==null){
            return;
        }




        //y轴坐标对应的数据
        List<Float> xyYValue = new ArrayList<>();
        for (int i = 0; i < 7; i++) {//Y轴的刻度值
            xyYValue.add((float)(i *30));
        }
        //x轴坐标对应的数据
        List<String> oneXValue = new ArrayList<>();
        List<String> disXValue = new ArrayList<>();
        List<Integer> xPointColor = new ArrayList<>();
        List<Integer> xPointColor2 = new ArrayList<>();
        Map<String, Float> xyValue = new HashMap<>();
        Map<String, Float> maiboValue = new HashMap<>();


        float newesXY = 0;
        float newesXL = 0;


        if (reportData.resultData.chartList!=null){


        //dateType:日期类型 1:年 2:月 3周: 4:天
        //measureType:1:血糖 2:血压 3:血氧 4:体温 5:尿酸 6:总胆固醇 7:人体成份
        for (int i=0;i<reportData.resultData.chartList.size();i++){
            BO_R.ResultDataBean.ChartListBean data = reportData.resultData.chartList.get(i);


            if (data.pulseAvg==0||data.bloodoxygenAvg==0){
                continue;
            }
            String timeParam="";
            String disTimeParam="";
            if (reportData.resultData.dateType==1){
                Date date= TimeUtils.parseFormatter91Time(data.timeParam);
                timeParam= CommonUtils.getMonths(NumUtils.string2Int(TimeUtils.formatTime12(date.getTime())));
                disTimeParam=timeParam;
            }else if (reportData.resultData.dateType==2){
                timeParam=String.format(getString_(R.string.Week_int),data.timeParam);
                disTimeParam=timeParam;
            }else if (reportData.resultData.dateType==3){
                Date date2= TimeUtils.parseFormatter3Time(data.timeParam);
                timeParam=TimeUtils.formatTime11(date2.getTime());
                disTimeParam=timeParam;
            }else if (reportData.resultData.dateType==4){
                Date date3= TimeUtils.parseFormatter1Time(data.timeParam);
                timeParam=TimeUtils.formatTime13(date3.getTime());
                disTimeParam=TimeUtils.formatTime4(date3.getTime());
            }

            oneXValue.add(timeParam);
            disXValue.add(disTimeParam);

            xyValue.put(timeParam, (float) data.bloodoxygenAvg);
            newesXY=data.bloodoxygenAvg;
            xPointColor.add(levelColors[BOManager.getBOLevel(data.bloodoxygenAvg)]);
            xPointColor2.add(levelColors[2]);
            maiboValue.put(timeParam, (float) data.pulseAvg);
            newesXL=data.pulseAvg;


        }

        }

        if (reportData.resultData.summaryList!=null&&reportData.resultData.summaryList.size()>0){
            setCb8Title(xueyang_xy_cb8,2, NumUtils.disIntZero((int) reportData.resultData.summaryList.get(0).bloodoxygenMin,N2));
            setCb8Title(xueyang_xy_cb8,3,NumUtils.disIntZero((int) reportData.resultData.summaryList.get(0).bloodoxygenMax,N2));
            setCb8Title(xueyang_xy_cb8,4,NumUtils.disIntZero( reportData.resultData.summaryList.get(0).bloodoxygenAvg,N2));

            setCb8SrcRes(xueyang_xy_cb8, EHCCommonUtils.getDisplaySrcRes(reportData.resultData.summaryList.get(0).bloodoxygenAvg,newesXY));

            setCb8Title(xueyang_xl_cb8,2,NumUtils.disIntZero( reportData.resultData.summaryList.get(0).pulseMin,N2));
            setCb8Title(xueyang_xl_cb8,3,NumUtils.disIntZero( reportData.resultData.summaryList.get(0).pulseMax,N2));
            setCb8Title(xueyang_xl_cb8,4,NumUtils.disIntZero( reportData.resultData.summaryList.get(0).pulseAvg,N2));
            setCb8SrcRes(xueyang_xl_cb8, EHCCommonUtils.getDisplaySrcRes(reportData.resultData.summaryList.get(0).pulseAvg,newesXL));
        }

        if (trend_xy_xy_chartview3!=null) {
            trend_xy_xy_chartview3.setxPointColor(xPointColor);
            trend_xy_xy_chartview3.setdisXValue(disXValue);
            trend_xy_xy_chartview3.setValue(xyValue,oneXValue,xyYValue);
            trend_xy_xy_chartview3.src2end();
        }
        if (trend_xy_xl_chartview3!=null){
            trend_xy_xl_chartview3.setxPointColor(xPointColor2);
            trend_xy_xl_chartview3.setdisXValue(disXValue);
            trend_xy_xl_chartview3.setValue(maiboValue,oneXValue,xyYValue);
            trend_xy_xl_chartview3.src2end();
        }


    }

    @Override
    protected void initView() {
        super.initView();
        FV();
    }

    private void FV() {
        xueyang_xy_cb8=mRootView.findViewById(R.id.xueyang_xy_cb8);
        xueyang_xl_cb8=mRootView.findViewById(R.id.xueyang_xl_cb8);
        trend_xy_xy_chartview3=mRootView.findViewById(R.id.trend_xy_xy_chartview3);
        trend_xy_xl_chartview3=mRootView.findViewById(R.id.trend_xy_xl_chartview3);
        xy_cb7=mRootView.findViewById(R.id.xy_cb7);

        if (AppUtils.en==AppUtils.getLocalStr()){
            xy_cb7.setTitleSizes(13);
            xueyang_xy_cb8.setTitleSizes(14);
            xueyang_xl_cb8.setTitleSizes(14);
        }

        trend_xy_xy_chartview3.warringTem=1000;
        trend_xy_xl_chartview3.warringTem=1000;
        trend_xy_xy_chartview3.yOriStart=0;
        trend_xy_xl_chartview3.yOriStart=0;
        trend_xy_xy_chartview3.displayInt=true;
        trend_xy_xl_chartview3.displayInt=true;

    }
}
